<template>
    <div>
        <yd-cell-item>
            <span slot="left">物品质量</span>
            <yd-rate slot="right" v-model="quality" :showText="['很差','较差','一般','较好','很好']"></yd-rate>
        </yd-cell-item>
        <yd-cell-item>
            <span slot="left">响应速度</span>
            <yd-rate slot="right" v-model="sudu" :showText="['很差','较差','一般','较好','很好']"></yd-rate>
        </yd-cell-item>
        <yd-cell-item>
            <span slot="left">服务态度</span>
            <yd-rate slot="right" v-model="fuwu" :showText="['很差','较差','一般','较好','很好']"></yd-rate>
        </yd-cell-item>
        <div class="small-space-background"></div>
        <yd-cell-item>
            <yd-textarea slot="right" placeholder="详细评价" maxlength="200"  v-model="desContent"></yd-textarea>
        </yd-cell-item>
        <div class="small-space-background"></div>

        <yd-button  size="large" type="primary" @click.native="evaluateClick" style="background-color:#3cc8a8;color:white;height: 40px">确定</yd-button>


    </div>
</template>

<script>
    import {orderevaluate,voucherevaluate} from "../../pcof/post";
    import {userInfoData} from '../../globalVariables'

    export default {
        name: "customEvaluate",
        data() {
            return {
                uuid:'',
                type: '',//1 是办公用品 2是凭证请领
                quality:0,
                sudu:0,
                fuwu:0,
                desContent:'',

            };
        },
        created()
        {
            this.uuid = this.$route.params.uuid;
            this.type = this.$route.params.type;

        },
        methods:
        {
           async evaluateClick() {

              console.log(this.fuwu*2);
                   if (this.quality*2===0)
                   {
                       this.$dialog.toast({
                           mes: '物品质量请打分!',
                           timeout: 1500
                       });
                       return;
                   }else if (this.sudu*2===0)
                   {
                       this.$dialog.toast({
                           mes: '响应速度请打分!',
                           timeout: 1500
                       });
                       return;
                   }
                 else  if (this.fuwu*2===0)
                   {
                       this.$dialog.toast({
                           mes: '服务态度请打分!',
                           timeout: 1500
                       });
                       return;
                   }

               this.$dialog.loading.open('提交中...');
               if (this.type === '1') {
                    //  办公用品评价 orderevaluate
                    // mobile,orderUuid,quality,speed,altitude, content

                    //     mobile,orderUuid,
                    // *   quality质量  quality
                    // *  speed 速度  sudu
                    // *  altitude 服务态度 fuwu
                    var mobile=JSON.parse(localStorage.getItem(userInfoData)).mobile;
                    var  response = await  orderevaluate(mobile,this.uuid,
                        this.quality*2,
                        this.sudu*2,
                        this.fuwu*2,
                        this.desContent);
                    if (response.data.code === 200) {
                        this.$dialog.loading.close();
                        this.$dialog.toast({
                            mes: '评价成功',
                            timeout: 1500
                        });
                        this.$router.replace({name: 'wait'});

                    }else
                    {
                        this.$dialog.loading.close();
                        this.$dialog.toast({
                            mes:response.data.msg,
                            timeout: 1500
                        });
                    }


                }else if (this.type ==='2')
                {

                 // 凭证请领服务评价 voucherevaluate applicationUuid 数据的id
                 //    mobile,applicationUuid,quality,speed,altitude,content

                    // applicationUuid 数据的id
                // *   quality质量
                // *  speed 速度
                // *  altitude 服务态度

                    var mobile=JSON.parse(localStorage.getItem(userInfoData)).mobile;
                    var  response = await  voucherevaluate(mobile,this.uuid,
                        this.quality*2,
                        this.sudu*2,
                        this.fuwu*2,
                        this.desContent);
                    if (response.data.code === 200) {
                        this.$dialog.loading.close();
                        this.$dialog.toast({
                            mes: '评价成功',
                            timeout: 1500
                        });
                        this.$router.replace({name: 'wait'});

                    }else
                    {
                        this.$dialog.loading.close();
                        this.$dialog.toast({
                            mes:response.data.msg,
                            timeout: 1500
                        });
                    }

                }
            },



    },
    }
</script>

<style scoped>

</style>